package com.fxhy.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baby.bean.AgentInviteUserInfo;
import com.fxhy.bean.custom.AgentUserCustom;
import com.fxhy.bean.custom.MyInviteCustom;
import com.fxhy.mapper.InviteUserInfoMapper;
import com.fxhy.vo.InviteUserVo;

@Service
public class InviteUserInfoService {
	
	@Autowired
	private InviteUserInfoMapper inviteUserInfoMapper;

	public MyInviteCustom findInviteUser(AgentUserCustom user) {
		MyInviteCustom cunstom  = new MyInviteCustom();
		cunstom.setUseId(user.getUserId());
		cunstom.setUserName(user.getNickName());
		String num = inviteUserInfoMapper.findInviteUserCount(user.getUserId());
		cunstom.setInviteTotalUserCount(num == null ? 0 : Integer.parseInt(num));
		
		int inviteTotalRechargeTimes = 0;
		double inviteTotalRechargeMoney = 0.00;
		double myMoney = 0.00;
		
		//查询邀请的人
		List<InviteUserVo> list = inviteUserInfoMapper.findInviteRechargeUser(user.getUserId());
		for(InviteUserVo vo : list){
			inviteTotalRechargeTimes += vo.getRechargeTimes();
			inviteTotalRechargeMoney += vo.getRechargeMoney();
			myMoney += vo.getAgentMoney();
		}
		cunstom.setInviteRechargeUserCount(list.size());
		cunstom.setInviteTotalRechargeTimes(inviteTotalRechargeTimes);
		cunstom.setInviteTotalRechargeMoney(inviteTotalRechargeMoney);
		cunstom.setMyMoney(myMoney);
		cunstom.setInviteUsers(list);
		return cunstom;
	}

	public Integer saveInviteUserInfo(AgentInviteUserInfo inviteUser) {
		return inviteUserInfoMapper.insertInviteUser(inviteUser);
	}
}
